<?php 
Class proController extends appController
{
	
	public function ordering()
	{
		$id=isset($_POST['id'])?intval($_POST['id']):'';
		$val=isset($_POST['val'])?intval($_POST['val']):'';
		$result=Model('pro')->ordering($val,$id);
		print_r(json_encode($result));
	}
	public function index()
	{
		$cat_id=intval($_GET['id']);
		$page=isset($_REQUEST['page'])?intval($_REQUEST['page']):1;
		
		$art_list=Model('pro')->pro_list($page,$cat_id);
		
		
		$this->assign('pro_list',$art_list['data']);
		$this->assign('pro_page',$art_list['pagelink']);
		
		$this->assign('cat_id',$cat_id);
		$this->display('index.html');
		
	}
	public function del()
	{
		$id=isset($_REQUEST['id'])?$_REQUEST['id']:'';
		if(is_array($id))
		{
			foreach($id as $k=>$v)
			{
				$result=Model('pro')->del_pro($v);
			}
		}
		else
		{
			$result=Model('pro')->del_pro($id);
		}
		print_r(json_encode($result));
	}
	public function edit_pro()
	{
	
		$id=isset($_GET['id'])?intval($_GET['id']):'';
		$this->assign('id',$id);
		$art_info=Model('pro')->get_pro($id);
		$this->assign('pro',$art_info);
		
		$img_arr=Model('pro')->get_pro_img($id);
		$this->assign('pro_img',$img_arr);
		$this->assign('action','modified_pro');
		$this->display('product.html');
	
	}
	public function modified_pro()
	{
		
		$id=isset($_POST['id'])?$_POST['id']:'';
		$info['title']=isset($_POST['title'])?$_POST['title']:'';
		$info['abstract']=isset($_POST['abstract'])?$_POST['abstract']:'';
		$info['keywords']=isset($_POST['keywords'])?$_POST['keywords']:'';
		$info['model']=isset($_POST['model'])?$_POST['model']:'';
		$info['size']=isset($_POST['size'])?$_POST['size']:'';
		$info['content']=isset($_POST['content'])?$_POST['content']:'';
		$info['hits']=isset($_POST['hits'])?$_POST['hits']:'';
		$info['is_show']=isset($_POST['is_show'])?$_POST['is_show']:'';
		$info['is_push']=isset($_POST['is_push'])?$_POST['is_push']:'';
		$img_array=isset($_POST['img_array'])?(array)json_decode($_POST['img_array']):'';
		$info['page_title']=isset($_POST['page_title'])?$_POST['page_title']:'';
		$info['created']=$_SERVER['REQUEST_TIME'];
		$info['page_title']=isset($_POST['page_title'])?$_POST['page_title']:'';
		$info['thumb']=isset($_POST['thumb'])?$_POST['thumb']:'';
		
		$result=Model('pro')->update_pro($info,$img_array,$id);
		
		
		$data=array('error'=>0,'content'=>'','url'=>'');
		if($result['error']==0)
		{
			$data['content']=Lang('SUCCESS_EDIT');
			$data['url']="index.php?g=admin&m=content&a=add_content&id=".$this->get_cat_id($id,'product');
			
		}
		else
		{
			$data['content']=Lang('INVALID_OPERATION');
			//$data['url']=$_SERVER['REQUEST_URI'];
		}
		$this->showMsg($data);
	}
     public function add_pro()
	{
		
		$cat_id=isset($_GET['cat_id'])?intval($_GET['cat_id']):'';
		$this->assign('cat_id',$cat_id);
		$this->assign('action','insert_pro');
		$this->display('product.html');
	
	}
	
	public function insert_pro()
	{
		$info['cat_id']=isset($_POST['cat_id'])?$_POST['cat_id']:'';
		$info['title']=isset($_POST['title'])?$_POST['title']:'';
		$info['abstract']=isset($_POST['abstract'])?$_POST['abstract']:'';
		$info['keywords']=isset($_POST['keywords'])?$_POST['keywords']:'';
		$info['model']=isset($_POST['model'])?$_POST['model']:'';
		$info['size']=isset($_POST['size'])?$_POST['size']:'';
		$info['content']=isset($_POST['content'])?$_POST['content']:'';
		$info['hits']=isset($_POST['hits'])?$_POST['hits']:'';
		$info['is_show']=isset($_POST['is_show'])?$_POST['is_show']:'';
		$info['is_push']=isset($_POST['is_push'])?$_POST['is_push']:'';
		$img_array=isset($_POST['img_array'])?(array)json_decode(stripslashes($_POST['img_array'])):'';
		$info['page_title']=isset($_POST['page_title'])?$_POST['page_title']:'';
		$info['created']=$_SERVER['REQUEST_TIME'];
		$info['page_title']=isset($_POST['page_title'])?$_POST['page_title']:'';
		$info['thumb']=isset($_POST['thumb'])?$_POST['thumb']:'';
		
		if($info['title']=='')
		{
			$data['content']=Lang('NAME_EMPTY');
			$this->showMsg($data);
		}
		$result=Model('pro')->create_pro($info,$img_array);
		$data=array('error'=>0,'content'=>'','url'=>'');
		if($result['error']==0)
		{
			$data['content']=Lang('SUCCESS_ADD');
			$data['url']="index.php?g=admin&m=content&a=add_content&id=".$info['cat_id'];
			
		}
		else
		{
			$data['content']=Lang('INVALID_OPERATION');
			//$data['url']=$_SERVER['REQUEST_URI'];
		}
		$this->showMsg($data);
	}
	
	public function file()
	{
		
		$result=array('error'=>0,'url'=>'','num'=>'');
		
		$thumb_url=Model('image')->upload_image(current($_FILES),  'pro/'.date('Ym'));
		$result['url']=$thumb_url;
		$result['url_id']=$_GET['url_id'];
	
		$result['message']='';
		print_r(json_encode($result));
		exit();
	}
	
	

	
	
}